<?php
/**
 * // +----------------------------------------------------------------------
 * //            -------------------------
 * //           /   / ------------------\  \
 * //                                          \  \
 * //                                           /  /
 * //          /  /  ------------------- /  /
 * //        /  /  ----------------------
 * //      /  /
 * //      \  \
 * //        \  \  ------------------ /  /
 * //          \  \--------------------/
 * // +----------------------------------------------------------------------
 * // | Copyright (c) 2016 Sage  All rights reserved.
 * // +----------------------------------------------------------------------
 * // | Author: Sage
 * // +----------------------------------------------------------------------
 *
 */

/**
 * Created by PhpStorm.
 * User: Sage
 * Date: 2017/12/7
 * Time: 15:35
 */
namespace KysbsUtils\Service;
use KysbsUtils\Config;

/**
 * 响应服务
 * Class ResponseService
 * @package KysbsUtils\Service
 */
class ResponseService {
    /**
     * 成功返回
     * @param string $msg
     * @param array  $data
     * @param int    $status
     *
     * @return string
     */
    function echoSuccess($data = [] ,$msg='成功'  ,  $code = 1) {
        if(empty($data) && !is_array($data))
            $data=[];
        if((string)$msg=='')$msg='系统繁忙';
        return (string)json_encode([
            'code' => $code ,
            'msg'=>$msg,
            'data'=>$data,
            'time'=>date('Y-m-d H:i:s')
        ],JSON_UNESCAPED_UNICODE);
    }

    /**
     * 错误返回
     * @param string $msg
     * @param array  $data
     * @param int    $status
     *
     * @return string
     */
    function echoError( $msg='系统繁忙' , $code = 0,$data = [] ) {
        if(empty($data) && !is_array($data))
            $data=[];
        if((string)$msg=='')$msg='系统繁忙';
        return (string)json_encode([
            'code' => (int)$code ,
            'msg'=>(string)$msg,
            'data'=>$data
        ],JSON_UNESCAPED_UNICODE);
    }

}